<template>
	<view>
		<block v-if="obj.id">
			<view class="bg">
				<view class="img-27">
					<video :src="obj.eventVideo"></video>
					<view class="display-a" v-if="user.id">
						<image class="act" :src="user.head"></image>
						<view class="name font-overflow">{{user.nickname}}</view>
						<image v-if="obj.releaseChannel == 1" class="img-29" src="../../static/29.png" @click="getOpenHomepage()"></image>
					</view>
					<view v-else style="height: 100rpx;"></view>
					<scroll-view class="frame" :scroll-y="true">
						<view class="color_FFFFFF">{{obj.activityDescription}}</view>
					</scroll-view>
				</view>
				
				<view style="height: 160rpx;"></view>
				<image v-if="uid" @click="handleOperate()" class="img-28" src="../../static/28.png"></image>
				<image v-else @click="handleOperate()" class="img-joinActivity" src="../../static/joinActivity.png"></image>
				
			</view>
		</block>
		<view v-if="uid">
			<drag-button :isDock="true" @btnClick="myPrize()" @btnTouchstart="btnTouchstart"
				@btnTouchend="btnTouchend" />
		</view>
	</view>
</template>

<script>
	import dragButton from "@/components/drag-button/drag-button.vue";

	export default {
		components: {
			dragButton
		},
		data() {
			return {
				id: '', //活动id
				uid: '',
				obj: {}, //活动数据
				user: {}, //抖音，快手用户数据
			}
		},

		onLoad(options) {

			// if (process.env.NODE_ENV === 'development') {
			// 	// this.uid = 228;
			// 	this.id = 147;
			// 	this.Duser();
			// 	this.detail();
			// }

			if (options.uid) {
				this.uid = options.uid;
				// this.Duser();
			}
			if (options.id) {
				this.id = options.id;
				this.detail();
			}
		},

		onShow() {
			this.$at.releaseKey('videoForwarding');
		},

		methods: {
			
			//抖音跳转商家主页
			async getOpenHomepage() {
				const result = await this.$http.get({
					url: this.$api.getUserProfile,
					data: {
						openId: this.user.openId,
					}
				});
				if (result.code == 2000) {
					window.location.href = result.data.data.schema;
				} else {
					this.$sun.toast(result.msg, 'none');
				}
				
			},
			
			// 	//活动
			handleOperate() {

				if (!this.obj.eventVideo) {
					uni.showModal({
						title: '提示',
						content: '视频已用完,请联系商家上传更多作品!',
						showCancel: false,
						confirmText: '确定',
						confirmColor: '#4630D3',
						success: res => {
							if (res.confirm) {

							}
						}
					});
				}

				//releaseChannel //发布渠道 1.抖音2.视频号3.快手
				//activityType 1.视频快推2.幸运大转盘3.幸运九宫格4.卡劵活动 5硬件活动
				if (this.obj.releaseChannel == 1) {
					if (this.obj.activityType == 1 || this.obj.activityType == 5) {
						this.sendVideo();
					}
				} 
				
				if (this.obj.releaseChannel == 3) {
					if (this.obj.activityType == 1 || this.obj.activityType == 5) {
						this.getForward();
					}
				} 

				// if (this.obj.activityType == 2) {
				// 	uni.navigateTo({
				// 		url: '/pages/index/previewTurntable?id=' + this.id + '&uid=' + this.uid
				// 	})
				// }
				// if (this.obj.activityType == 3) {
				// 	uni.navigateTo({
				// 		url: '/pages/index/previewSquared?id=' + this.id + '&uid=' + this.uid
				// 	})
				// }
				// if (this.obj.activityType == 4) {
				// 	uni.navigateTo({
				// 		url: '/pages/index/previewCoupon?id=' + this.id + '&uid=' + this.uid
				// 	})
				// }

			},

			//快手转发
			async getForward() {
				this.$at.uniDoFunc({
					// 键名
					key: 'videoForwarding',
					// 是否立即触发,默认触发
					// instant: true,
					success: async () => {
						//锁定
						this.$at.lockKey('videoForwarding');
						const result = await this.$http.get({
							url: this.$api.videoForwarding,
							data: {
								shopId: this.id,
								uid: this.uid
							}
						});
						if (result.code == 2000) {
							this.$at.releaseKey('videoForwarding');
							uni.showModal({
								title: '提示',
								content: result.msg,
								showCancel: false,
								success: res => {

								}
							});
						} else {
							this.$at.releaseKey('videoForwarding');
							this.$sun.toast(result.msg, 'none');
						}
					}
				});
			},

			//我的奖品
			myPrize() {
				uni.navigateTo({
					url: '/pages/index/myPrize?uid=' + this.uid + '&id=' + this.id + '&releaseChannel='+this.obj.releaseChannel
				})
			},

			//转发
			async sendVideo() {
				
				uni.showLoading({
					title: ''
				})
				const result = await this.$http.get({
					url: this.$api.getShare,
					data: {
						uid: this.uid,
						shopId: this.id,
					}
				});
				if (result.code == 2000) {
					uni.hideLoading();
					this.jump(result.data);
				} else {
					uni.hideLoading();
					this.$sun.toast(result.msg);
				}
			},

			jump(dyShares) {
				this.$at.uniDoFunc({
					// 键名
					key: 'getShare',
					// 是否立即触发,默认触发
					// instant: true,
					success: async () => {
						//锁定
						this.$at.lockKey('submit');
						/*
						 * video_path:视频url
						 * image_path:图片url
						 * share_to_publish ? 0 默认(跳转视频编辑页) : 1（跳转视频发行页）
						 * hashTags 转发视频 话题
						 * s_type 挂载类型 1 抖音POI（地址） 2小程序 3 没有
						 *  app_id 小程序id
						 *  app_title 小程序标题
						 *  app_url 小程序地址
						 *  poi_id POI地址
						 */
						// const hashTags = [dyShares.hashtag_list];
						const url = new URL('snssdk1128://openplatform/share');
						var query = url.searchParams;
						query.append('hashtag_list', JSON.stringify(dyShares.hashtag_list));
						query.append('client_key', dyShares.client_key);
						query.append('state', dyShares.state);
						query.append('nonce_str', dyShares.nonce_str);
						query.append('timestamp', dyShares.timestamp);
						query.append('signature', dyShares.signature);
						query.append('share_type', dyShares.share_type);
						query.append('video_path', dyShares.video_path);
						query.append('title', dyShares.tilte);
						if (dyShares.poi_id) {
							query.append('poi_id', dyShares.poi_id);
						}
						// query.append("image_path", "https://sf3-cdn-tos.douyinstatic.com/obj/douyin-open-static/tiktok.open/home/d_logo.png")
						query.append('share_to_publish', dyShares.share_to_publish);

						if (dyShares.mountType == 2) {
							query.append(
								'micro_app_info',
								JSON.stringify({
									appId: dyShares.app_id,
									appTitle: dyShares.app_title,
									appUrl: dyShares.app_url
								})
							);
						}
						window.location.href = url;
						setTimeout(() => {
							this.$at.releaseKey('submit');
						}, 2500);
					}
				});
			},
			
			//抖音、快手用户数据
			async dUser() {
				const result = await this.$http.get({
					url: this.$api.selectMerchantFollowMe,
					data: {
						merchantId: this.obj.merchantId,
					}
				});
				if (result.code == 2000) {
					this.user = result.data;
				} else {
					this.$sun.toast(result.msg, 'none');
				}
			},
			
			// 	//抖音、快手用户数据
			// async Duser() {
			// 	const result = await this.$http.get({
			// 		url: this.$api.selectMerchantFollowMe,
			// 		data: {
			// 			id: this.uid,
			// 		}
			// 	});
			// 	if (result.code == 2000) {
			// 		this.user = result.data;
			// 	} else {
			// 		this.$sun.toast(result.msg, 'none');
			// 	}
			// },

			// 	//活动详情
			async detail() {
				const result = await this.$http.get({
					url: this.$api.selectGetId,
					data: {
						id: this.id,
					}
				});
				if (result.code == 2000) {
					this.obj = result.data;
					this.$sun.title(this.obj.activityName);
					this.dUser();
					if (!this.obj.eventVideo) {
						uni.showModal({
							title: '提示',
							content: '视频已用完,请联系商家上传更多作品!',
							showCancel: false,
							confirmText: '确定',
							confirmColor: '#4630D3',
							success: res => {
								if (res.confirm) {

								}
							}
						});
					}
				} else {
					this.$sun.toast(result.msg, 'none');
				}
			},

		}
	}
</script>

<style lang="scss">
	.look {
		text-align: center;
		color: #FFFFFF;
		padding-bottom: 20rpx;
		text-decoration: underline;
	}

	.frame {
		// border: 1px solid red;
		width: 640rpx;
		height: 420rpx;
		margin: 120rpx 48rpx 0;
	}

	.img-28 {
		width: 554rpx;
		height: 126rpx;
		position: fixed;
		bottom: 40rpx;
		left: 98rpx;
	}
	
	.img-joinActivity {
		width: 512rpx;
		height: 103rpx;
		position: fixed;
		bottom: 40rpx;
		left: 118rpx;
	}

	.name {
		font-size: 32rpx;
		color: #FFFFFF;
		width: 280rpx;
	}

	.act {
		width: 100rpx;
		height: 100rpx;
		border-radius: 100rpx;
		// background-color: #a1a1a1;
		// color: #FFFFFF;
		// padding: 10rpx 20rpx;
		margin: 0 20rpx 0 60rpx;
	}

	.img-29 {
		width: 180rpx;
		height: 66rpx;
		margin-left: auto;
		margin-right: 60rpx;
	}

	uni-video {
		width: 598rpx;
		height: 336rpx;
		margin: 168rpx 48rpx 120rpx 70rpx;
		border-radius: 4rpx;
	}

	.img-27 {
		width: 718rpx;
		height: 1316rpx;
		background: url('~static/27.png');
		background-repeat: no-repeat;
		background-size: contain;
		margin: 0 16rpx 20rpx;
	}

	.bg {
		width: 750rpx;
		height: 1494rpx;
		background: url('~static/26.png');
		background-repeat: no-repeat;
		background-size: contain;
	}

	page {
		border-top: 0;
		background-color: #4F29D2;
		padding-top: 14rpx;
		padding-bottom: 20rpx;
	}

	page {
		background: linear-gradient(180deg, #462CD4 0%, #5129D2 100%);
	}
</style>